public class PrimePrinterOptimized {
    public static void main(String[] args) {
        int max = 20000;
        boolean[] isPrime = new boolean[max + 1];

                for (int i = 2; i <= max; i++) {
            isPrime[i] = true;
        }

                for (int p = 2; p * p <= max; p++) {
            if (isPrime[p]) { 
                
                for (int multiple = p * p; multiple <= max; multiple += p) {
                    isPrime[multiple] = false;
                }
            }
        }

                int count = 0;
        for (int i = 2; i <= max; i++) {
            if (isPrime[i]) {
                System.out.print(i + "\t");
                count++;
                if (count % 5 == 0) {
                    System.out.println();
                }
            }
        }
    }
}